package interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import dao.BrandDAO;
import dao.ConditionDAO;
import dao.DealsDAO;
import dao.ProductCatalogDAO;
import pojo.Brand;
import pojo.Condition;
import pojo.Deals;
import pojo.Productcatalog;

public class PrepareDataInterceptor extends HandlerInterceptorAdapter  {
	
	@Autowired
	private ProductCatalogDAO productCatalogDAO;
	@Autowired
	private BrandDAO brandDAO;
	@Autowired
	private ConditionDAO conditionDAO;
	@Autowired
	private DealsDAO dealsDAO;
	//before the actual handler will be executed
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		
		List<Productcatalog> listProductCatalog = productCatalogDAO
				.getProductCatalogList();
		request.setAttribute("listProductCatalog", listProductCatalog);
		List<Brand> listBrand = brandDAO.getBrandList();
		request.setAttribute("listBrand", listBrand);
		List<Condition> listCondition = conditionDAO.getConditionList();
		request.setAttribute("listCondition", listCondition);
		List<Deals> listDeals = dealsDAO.getDealsList();
		request.setAttribute("listDeals", listDeals);
		
 
		return true;
	}
}
